<template>
  <div style="position: fixed; right: 20px;bottom: 50px; z-index: 2">
    <div class="right-box">
      <ul>
        <li>
          <!-- <img class="icon-img" src="../../assets/img/1-2.png" alt> -->
          <div class="move-box">
            <h3>010-53857596</h3>
            <p>工作日 9:00～17:30</p>
          </div>
        </li>
        <li>
          <!-- <img class="icon-img" src="../../assets/img/2-2.png" alt> -->
          <div class="move-box">
            <h3>marketing@loreage.com</h3>
            <p>欢迎邮件咨询</p>
          </div>
        </li>
        <li>
          <!-- <img class="icon-img" src="../../assets/img/3-2.png" alt> -->
          <div class="move-boxImg">
            <div class="qr-code" v-if="qrList">
              <div class="code-item">
                <img
                  v-if="qrList.children[0]&& qrList.children[0].indexImg"
                  :src="returnImg(qrList.children[0].indexImg)"
                  :alt="qrList.children[0].indexName"
                >
              </div>
            </div>
            <p>扫码关注</p>
          </div>
        </li>
        <li v-if="btnShow" @click="backTop">
          <!-- <img class="icon-img" src="../../assets/img/icon.png" alt> -->
        </li>
      </ul>
      <!-- <el-button v-if="btnShow" class="scaleBig" @click="backTop">
          <img style="width: 20px;" src="../../assets/icon/backTop.svg" alt="">
      </el-button>-->
    </div>
  </div>
</template>

<script>
import { onMounted, ref } from "vue";
import { getFooter } from "@/api/PC-Home";
export default {
  setup() {
    const btnShow = ref(false);
    let qrList = ref(null);
    let timer = null;
    onMounted(() => {
      window.addEventListener("scroll", scrollToTop);
      getFooters();
    });
    function getFooters() {
      getFooter().then(res => {
        let data = res.data;
        data.map(item => {
          if (item.id === "603") {
            qrList.value = item;
          }
        });
      });
    }
    function backTop() {
      timer = setInterval(function() {
        let backTop =
          window.pageYOffset ||
          document.documentElement.scrollTop ||
          document.body.scrollTop;
        let speedTop = backTop / 5;
        document.documentElement.scrollTop = backTop - speedTop;
        if (backTop <= 10) {
          clearInterval(timer);
        }
      }, 30);
    }
    function scrollToTop() {
      let pageLookHeight =
        document.documentElement.clientHeight || document.body.clientHeight;
      let scroll = document.documentElement.scrollTop;

      if (scroll >= pageLookHeight) {
        btnShow.value = true;
      } else {
        btnShow.value = false;
      }
    }
    function returnImg(url) {
      return process.env.VUE_APP_URL + "/" + url;
    }
    return {
      top,
      btnShow,
      timer,
      backTop,
      scrollToTop,
      qrList,
      getFooters,
      returnImg
    };
  }
};
</script>

<style scoped lang="scss">
/*鼠标经过放大*/
.scaleBig {
  transition: transform 0.5s ease;
}
.scaleBig:hover {
  transform: scale(1.4);
}
.right-box {
  width: 50px;
  height: auto;
  background: #fff;
  border-radius: 30px;
  box-shadow: 0 0 10px rgba(0, 17, 67, 0.3);
  padding: 12px 0;
  // overflow: hidden;
}
.right-box ul li {
  width: 100%;
  height:48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  &:nth-of-type(1){
    background: url("../../assets/img/1-2.png") no-repeat;
  background-position: 10px 10px;
  background-size: 28px 28px;
  }
  &:nth-of-type(2){
    background: url("../../assets/img/2-2.png") no-repeat;
    background-position: 10px 10px;
    background-size:28px 28px;
  }
  &:nth-of-type(3){
    background: url("../../assets/img/3-2.png") no-repeat;
    background-position: 10px 10px;
    background-size:28px 28px;
  }
  &:nth-of-type(4){
    background: url("../../assets/img/4-2.png") no-repeat;
    background-position: 10px 10px;
    background-size:28px 28px;
  }
  &:nth-of-type(1):hover{
    background: url("../../assets/img/1-1.png") no-repeat;
    background-position: 10px 10px;
    background-size:28px 28px;
    transform: scale(0.9);
    transition: 1s all ease;
  }
  &:nth-of-type(2):hover{
    background: url("../../assets/img/2-1.png") no-repeat;
    background-position: 10px 10px;
    background-size:28px 28px;
    transform: scale(0.9);
    transition: 1s all ease;
  }
  &:nth-of-type(3):hover{
    background: url("../../assets/img/3-1.png") no-repeat;
    background-position: 10px 10px;
    background-size:28px 28px;
    transform: scale(0.9);
    transition: 1s all ease;
  }
  &:nth-of-type(4):hover{
    background: url("../../assets/img/4-1.png") no-repeat;
    background-position: 10px 10px;
    background-size:28px 28px;
    transform: scale(0.9);
    transition: 1s all ease;
  }
}
// .right-box ul li:hover {
//   background: #1790ff;
// }
.icon-img {
  width: 28px;
  height: 28px;
}
.move-box {
  display: none;
  position: absolute;
  min-width: 200px;
  width: auto;
  height: auto;
  right: 60px;
  top: 0;
  background: #fff;
  font-size: 14px;
  padding: 10px;
  text-align: left;
  box-shadow: 0 0 10px rgba(0, 17, 67, 0.3);
}
.move-box h3 {
  font-size: 20px;
  color: #1790ff;
}
.right-box ul li:nth-of-type(1):hover .move-box {
  display: block;
}
.right-box ul li:nth-of-type(2):hover .move-box {
  display: block;
}
.move-boxImg {
  display: none;
  position: absolute;
  width: 120px;
  height: auto;
  right: 60px;
  bottom: 0;
  background: #fff;
  font-size: 14px;
  padding: 10px;
  text-align: center;
  box-shadow: 0 0 10px rgba(0, 17, 67, 0.3);
}
.right-box ul li:nth-of-type(3):hover .move-boxImg {
  display: block;
  bottom: 0;
  img {
    width: 100%;
  }
}
@media only screen and (max-device-width: 768px) {
  .right-box{
    display: none
  }
}
</style>